package com.tianhui.consignortwofei.mvp.ui.activity.hetong.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonResponse;
import com.fgs.common.CommonView;
import com.fgs.common.entity.SelectItemInfo;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.DateUtil;
import com.fgs.common.widget.SelectDialog;
import com.fgs.common.widget.TabSwitchView;
import com.fgs.common.widget.itemView.ClickItemView;
import com.fgs.common.widget.itemView.InputItemView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractInfo;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractTypeInfo;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.AdvancePaymentContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.CashDepositContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.DianJiaDepositContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.FuturesDepositContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.IContractType;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.IContractTypeView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.NoCashDepositContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.ZhangQiDepositContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.AdvancePaymentView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.CashDeliveryView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.DianJiaDepositView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.FuturesDepositView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.NoCashDepositView;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view.ZhangQiDepositView;
import com.xuexiang.xui.widget.edittext.MultiLineEditText;
import com.xuexiang.xui.widget.picker.widget.TimePickerView;
import com.xuexiang.xui.widget.picker.widget.builder.TimePickerBuilder;
import com.xuexiang.xui.widget.picker.widget.configure.TimePickerType;
import com.xuexiang.xui.widget.picker.widget.listener.OnTimeSelectListener;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2021/5/19
 * @description
 **/
public class ContractAddStepOneActivityNew extends BaseContractAddActivity {

    @BindView(R.id.activity_contract_add_step_one_contractNumberInputItemView)
    protected InputItemView mContractNumberInputItemView;
    @BindView(R.id.activity_contract_add_step_one_contractStandardTypeClickItemView)
    protected ClickItemView mContractStandardTypeClickItemView;
    @BindView(R.id.activity_contract_add_step_one_contractTypeClickItemView)
    protected ClickItemView mContractTypeClickItemView;

    @BindView(R.id.activity_contract_add_step_one_packageStandardsClickItemView)
    protected ClickItemView mPackageStandardsClickItemView;
    @BindView(R.id.activity_contract_add_step_one_deliveryPlaceClickItemView)
    protected ClickItemView mDeliveryPlaceClickItemView;


    @BindView(R.id.civ_jiesuan_type)
    protected ClickItemView civ_jiesuan_type;


    //供方配送
    @BindView(R.id.activity_contract_add_step_one_supplierDistributionLinearLayout)
    protected LinearLayout mSupplierDistributionLinearLayout;
    @BindView(R.id.activity_contract_add_step_one_supplierDistributionClickItemView)
    protected ClickItemView mSupplierDistributionClickItemView;
    @BindView(R.id.activity_contract_add_step_one_supplierDistributionEditText)
    protected MultiLineEditText mSupplierDistributionEditText;
    @BindView(R.id.activity_contract_add_step_one_supplierDistributionEditTextView)
    protected TextView mSupplierDistributionEditTextView;


    //需方自提
    @BindView(R.id.activity_contract_add_step_one_demanderPickLinearLayout)
    protected LinearLayout mDemanderPickLinearLayout;
    @BindView(R.id.activity_contract_add_step_one_demanderPickInputItemView)
    protected InputItemView mDemanderPickInputItemView;

    //交货与结算货款
    @BindView(R.id.activity_contract_add_step_one_contractTypeViewFrameLayout)
    protected FrameLayout mContractTypeViewFrameLayout;


    @BindView(R.id.activity_contract_add_step_one_litigationClauseEditText)
    protected MultiLineEditText mLitigationClauseEditText;
    @BindView(R.id.activity_contract_add_step_one_litigationClauseEditTextView)
    protected TextView mLitigationClauseEditTextView;

    @BindView(R.id.tv_search_bianhao)
    protected TextView tv_search_bianhao;

    //是否盖章
    @BindView(R.id.tsb_gaizhang)
    protected TabSwitchView tsb_gaizhang;

    private SelectDialog mContractStandardTypeSelectDialog;
    private SelectDialog mContractTypeSelectDialog;
    private SelectDialog mPackageStandardsSelectDialog;
    private SelectDialog mDeliveryPlaceSelectDialog;
    private SelectDialog mJieSuanSelectDialog;


    private boolean isSupplierDistributionEditable;

    private boolean isLitigationClauseEditable;

    protected IContractTypeView iContractTypeView;


    @Override
    public int getLayoutId() {
        return R.layout.activity_contract_add_step_one_new;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @Override
    public ContractInfo getSaveInfo() {
        String contractNumber = mContractNumberInputItemView.getContent();
        if (TextUtils.isEmpty(contractNumber)) {
            showToast("请输入合同编号");
            return null;
        }
        mContractInfo.contractno = contractNumber;

//        if (mContractInfo.methodtype.equals("1")) {
//            String supplierDistributionDate = mSupplierDistributionClickItemView.getContent();
////            if (TextUtils.isEmpty(supplierDistributionDate)) {
////                showToast("请选择供方配送时间");
////                return null;
////            }
//
            String supplierDistribution = mSupplierDistributionEditText.getContentText();
        if (TextUtils.isEmpty(contractNumber)) {
            showToast("请输入产品交付地点");
            return null;
        }
            mContractInfo.placemethod = supplierDistribution;
//        } else {
//            String demanderPickContent = mDemanderPickInputItemView.getContent();
//            mContractInfo.otherplacemethod = demanderPickContent;
//        }


        if (TextUtils.isEmpty(mContractInfo.contracttype)) {
            showToast("请选择合同类型");
            return null;
        }

        ContractInfo contractInfo = iContractTypeView.getContractViewInfo(mContractInfo);
        if (contractInfo == null) {
            return null;
        }
        mContractInfo = contractInfo;

        String litigationClause = mLitigationClauseEditText.getContentText();
        mContractInfo.complain = litigationClause;


        return mContractInfo;
    }

    @Override
    public void initData() {
//        mContractInfo.methodtype = "1";
//        mDeliveryPlaceClickItemView.setContent("1、产品由需方自提");

        mContractInfo.packagetype = "原包装袋，25公斤/包。";
//        mContractInfo.packagetype ="原包袋装，25公斤/包或吨/包。";
//        mPackageStandardsClickItemView.setContent("原包袋装，25公斤/包或吨/包。");
        mPackageStandardsClickItemView.setContent("原包袋装，25公斤/包。");

        mContractInfo.qualitystandard = "标准";
        mContractStandardTypeClickItemView.setContent("标准");

//        civ_jiesuan_type.setContent("银行汇款");
//        mContractInfo.paytype = "2";

        mContractInfo.isblack = "1";

    }


    @Override
    public void initListener() {
        //是否推送
        tsb_gaizhang.setOnTabCheckedChangeListener(new TabSwitchView.OnTabCheckedChangeListener() {
            @Override
            public void onCheckedChanged(int position, String item, String value) {
                mContractInfo.isblack = value;
            }
        });

    }

    @Override
    public void initView() {

        mLitigationClauseEditText.getEditText().setEnabled(false);

        mSupplierDistributionEditText.getEditText().setEnabled(false);

//        mSupplierDistributionEditText.setContentText("     年    月    日前送至需方           。");

        mSupplierDistributionEditText.setContentText("汽车运输送至需方           。");

        mLitigationClauseEditText.setContentText("因执行本合同所发生的争议，双方应友好协商解决，如双方协商不能解决时，应向合同签订地秦皇岛市海港区人民法院提起诉讼。若乙方违约，甲方按合同约定保护自身利益所产生的包括但不限于诉讼费、保全费、执行费、律师费、差旅费等均由乙方负责。");
    }

    @OnClick(R.id.activity_contract_add_step_one_contractStandardTypeClickItemView)
    public void selectContractStandardType() {
        showContractStandardTypeDialog();
    }

    @OnClick(R.id.activity_contract_add_step_one_contractTypeClickItemView)
    public void selectContractType() {
        showContractTypeDialog();
    }

    private void showContractStandardTypeDialog() {
        if (mContractStandardTypeSelectDialog == null) {
            mContractStandardTypeSelectDialog = new SelectDialog<String>(this);
            mContractStandardTypeSelectDialog.setTitle("合同标准类型");
            mContractStandardTypeSelectDialog.setList(Arrays.asList(getResources().getStringArray(R.array.array_contract_standard_type)));
            mContractStandardTypeSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<String>() {
                @Override
                public void onItemClick(String itemContent, int position) {
                    mContractStandardTypeClickItemView.setContent(itemContent);
                    mContractInfo.qualitystandard = itemContent;
                }
            });
        }
        mContractStandardTypeSelectDialog.show();
    }

    private void showContractTypeDialog() {
        if (mContractTypeSelectDialog == null) {

            mContractTypeSelectDialog = new SelectDialog<ContractTypeInfo>(getContext());
            mContractTypeSelectDialog.setTitle("合同类型");
            mContractTypeSelectDialog.setList(getContractTypeList());
            mContractTypeSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<ContractTypeInfo>() {
                @Override
                public void onItemClick(ContractTypeInfo typeInfo, int position) {
                    mContractTypeClickItemView.setContent(typeInfo.getSelectItemText());
                    mContractInfo.contracttype = typeInfo.getSelectItemTextValue();

                    switch (position){
                        case 0:
                        case 3:
                            mSupplierDistributionEditText.setContentText("汽车运输送至需方           。");
                            break;
                        case 1:
                        case 2:
                        case 4:
                        case 5:
                        case 6:
                            mSupplierDistributionEditText.setContentText("");
                            break;
                    }

                    showContractTypeView(typeInfo.iContractTypeView);

                }
            });
        }
        mContractTypeSelectDialog.show();


    }

    protected void showContractTypeView(IContractTypeView iContractTypeView) {
        mContractTypeViewFrameLayout.removeAllViews();
        this.iContractTypeView = iContractTypeView;
        mContractTypeViewFrameLayout.addView(iContractTypeView.getContractView());
    }


    @OnClick(R.id.activity_contract_add_step_one_packageStandardsClickItemView)
    public void selectPackageStandards() {
        showPackageStandardsDialog();
    }

    @OnClick(R.id.activity_contract_add_step_one_deliveryPlaceClickItemView)
    public void selectDeliveryPlace() {
        showDeliveryPlaceDialog();
    }

    @OnClick(R.id.civ_jiesuan_type)
    public void selectJieSuan() {
        showJieSuanDialog();
    }

    private void showPackageStandardsDialog() {
        if (mPackageStandardsSelectDialog == null) {

            mPackageStandardsSelectDialog = new SelectDialog<String>(getContext());
            mPackageStandardsSelectDialog.setTitle("包装方法及标准");
            mPackageStandardsSelectDialog.setList(Arrays.asList(getResources().getStringArray(R.array.array_package_standard)));
            mPackageStandardsSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<String>() {
                @Override
                public void onItemClick(String content, int position) {
                    mPackageStandardsClickItemView.setContent(content);
                    mContractInfo.packagetype = content;
                }
            });
        }
        mPackageStandardsSelectDialog.show();


    }

    private void showDeliveryPlaceDialog() {
        if (mDeliveryPlaceSelectDialog == null) {

            mDeliveryPlaceSelectDialog = new SelectDialog<SelectItemInfo>(this);
            mDeliveryPlaceSelectDialog.setTitle("交货方式和地点");
            mDeliveryPlaceSelectDialog.setList(getDeliveryAddressList());
            mDeliveryPlaceSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<SelectItemInfo>() {
                @Override
                public void onItemClick(SelectItemInfo selectItemInfo, int position) {
                    mDeliveryPlaceClickItemView.setContent(selectItemInfo.getSelectItemText());
                    mContractInfo.methodtype = selectItemInfo.getSelectItemTextValue();
//                    if (position == 0) {
                        mSupplierDistributionLinearLayout.setVisibility(View.VISIBLE);
                        mDemanderPickLinearLayout.setVisibility(View.GONE);
//                    } else {
//                        mSupplierDistributionLinearLayout.setVisibility(View.GONE);
//                        mDemanderPickLinearLayout.setVisibility(View.VISIBLE);
//                    }
                }
            });
        }
        mDeliveryPlaceSelectDialog.show();


    }

    private List<SelectItemInfo> getDeliveryAddressList() {
        List<SelectItemInfo> infoList = new ArrayList<>();
        SelectItemInfo info;

//        info = new SelectItemInfo();
//        info.content = "供方配送";
//        info.value = "1";
//        infoList.add(info);
//
//        info = new SelectItemInfo();
//        info.content = "需方自提";
//        info.value = "2";
//        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "1、产品由需方自提";
        info.value = "1";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "2、甲方代办运输，运费由乙方承担，货物风险自甲方交付第一承运人起由乙方承担";
        info.value = "2";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "3、产品由甲方送货，运费由甲方承担";
        info.value = "3";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "4、转货权";
        info.value = "4";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "5、由甲方上游直发配送给乙方，具体送货时间以甲方上游送货时间为准，如与本合同约定送货时间不一致，不视为甲方逾期交货，甲方无需承担违约责任";
        info.value = "5";
        infoList.add(info);



        return infoList;
    }


    private void showJieSuanDialog() {
        if (mJieSuanSelectDialog == null) {

            mJieSuanSelectDialog = new SelectDialog<SelectItemInfo>(this);
            mJieSuanSelectDialog.setTitle("结算方式");
            mJieSuanSelectDialog.setList(getJieSuanList());
            mJieSuanSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<SelectItemInfo>() {
                @Override
                public void onItemClick(SelectItemInfo selectItemInfo, int position) {
                    civ_jiesuan_type.setContent(selectItemInfo.getSelectItemText());
                    mContractInfo.paytype = selectItemInfo.getSelectItemTextValue();
//                    if (position == 0) {
//                        mSupplierDistributionLinearLayout.setVisibility(View.VISIBLE);
//                        mDemanderPickLinearLayout.setVisibility(View.GONE);
//                    } else {
//                        mSupplierDistributionLinearLayout.setVisibility(View.GONE);
//                        mDemanderPickLinearLayout.setVisibility(View.VISIBLE);
//                    }

                }
            });
        }
        mJieSuanSelectDialog.show();


    }


    private List<SelectItemInfo> getJieSuanList() {
        List<SelectItemInfo> infoList = new ArrayList<>();
        SelectItemInfo info;

        info = new SelectItemInfo();
        info.content = "现金";
        info.value = "1";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "银行汇款";
        info.value = "2";
        infoList.add(info);

        info = new SelectItemInfo();
        info.content = "银行承兑汇票";
        info.value = "3";
        infoList.add(info);


        return infoList;
    }



    private List<ContractTypeInfo> getContractTypeList() {
        List<ContractTypeInfo> typeInfoList = new ArrayList<>();
        ContractTypeInfo typeInfo;

        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_advance);
        typeInfo.value = IContractType.ADVANCE_PAYMENT;
        typeInfo.iContractTypeView = new AdvancePaymentView(getContext(), new AdvancePaymentContract());
        typeInfoList.add(typeInfo);

        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_cash);
        typeInfo.value = IContractType.CASH_DEPOSIT;
        typeInfo.iContractTypeView = new CashDeliveryView(getContext(), new CashDepositContract());
        typeInfoList.add(typeInfo);

        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_no_cash);
        typeInfo.value = IContractType.NO_CASH_DEPOSIT;
        typeInfo.iContractTypeView = new NoCashDepositView(getContext(), new NoCashDepositContract());
        typeInfoList.add(typeInfo);

        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_futures);
        typeInfo.value = IContractType.FUTURES_DEPOSIT;
        typeInfo.iContractTypeView = new FuturesDepositView(getContext(), new FuturesDepositContract());
        typeInfoList.add(typeInfo);


        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_accounting);
        typeInfo.value = IContractType.ACCOUNTING_PERIOD;
        typeInfo.iContractTypeView = new ZhangQiDepositView(getContext(), new ZhangQiDepositContract());
        typeInfoList.add(typeInfo);

        typeInfo = new ContractTypeInfo();
        typeInfo.content = getResources().getString(R.string.string_contract_type_dianjia);
        typeInfo.value = IContractType.DIAN_JIA;
        typeInfo.iContractTypeView = new DianJiaDepositView(getContext(), new DianJiaDepositContract());
        typeInfoList.add(typeInfo);

        return typeInfoList;
    }


    @OnClick(R.id.tv_search_bianhao)
    public void searchBianHao() {
//        String content ="SA202308310091";
        String content = mContractNumberInputItemView.getContent();
        if (!TextUtils.isEmpty(content)) {
            getBianHaoResult(content);
        }else {
            showToast("搜索的合同编号不能为空");
        }

    }

    @OnClick(R.id.activity_contract_add_step_one_nextButton)
    public void next() {
        String peiSongTime = mSupplierDistributionClickItemView.getContent();
        if (TextUtils.isEmpty(peiSongTime)){
            showToast("提货时间未选择");
            return;
        }


        ContractInfo contractInfo = getSaveInfo();
        if (null==contractInfo){
            showToast("选择合同类型");
            return;
        }


        String fangShi = mDeliveryPlaceClickItemView.getContent();
        if (TextUtils.isEmpty(fangShi)){
            showToast("请选择交货方式和地点");
            return;
        }

        String payType = civ_jiesuan_type.getContent();
        if (TextUtils.isEmpty(payType)){
            showToast("请选择结算方式");
            return;
        }



        String jiaoFuDi = mSupplierDistributionEditText.getContentText();
        if (TextUtils.isEmpty(jiaoFuDi)){
            showToast("产品交付地不能为空");
            return;
        }
        contractInfo.placemethod=jiaoFuDi;


        contractInfo.methoddate=peiSongTime;
//        contractInfo.paywaychoose="1";
//        contractInfo.paywaychoosecontent=civ_leixing.getc
        if (contractInfo != null) {
            openNextActivity(contractInfo);
        }

    }

    protected void openNextActivity(ContractInfo contractInfo) {
        openNextStepActivity(contractInfo, ContractAddStepTwoActivity.class);
    }

    private TimePickerView mDistributionTimePickerView;

    @OnClick(R.id.activity_contract_add_step_one_supplierDistributionClickItemView)
    public void selectDistributionDate() {
        hideKeyboard();
        if (mDistributionTimePickerView == null) {

            mDistributionTimePickerView = new TimePickerBuilder(this, new OnTimeSelectListener() {
                @Override
                public void onTimeSelected(Date date, View v) {
                    String time = DateUtil.getStandardTime(date.getTime(), "yyyy-MM-dd");
                    mSupplierDistributionClickItemView.setContent(time);


                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(date);

                    int year = calendar.get(Calendar.YEAR);
                    int month = calendar.get(Calendar.MONTH) + 1;
                    int day = calendar.get(Calendar.DAY_OF_MONTH);

                    String supplierDistributionTip = "汽车运输送至需方           。";
//                    if (IContractType.CASH_DEPOSIT.equals(mContractInfo.contracttype)){
//                        supplierDistributionTip = year + " 年 " + DateUtil.addZero(month) + " 月 " + DateUtil.addZero(day) + " 日前送至需方           。";
//                    }
//                    String supplierDistributionTip = year + " 年 " + DateUtil.addZero(month) + " 月 " + DateUtil.addZero(day) + " 日前送至需方           。";


//                    mSupplierDistributionEditText.setContentText(supplierDistributionTip);
                }
            })
                    .setType(TimePickerType.DEFAULT)
                    .setTitleText("提货时间")
                    .build();
        }
        mDistributionTimePickerView.show();
    }

    @OnClick(R.id.activity_contract_add_step_one_litigationClauseEditTextView)
    public void litigationClauseEdit() {
        isLitigationClauseEditable = !isLitigationClauseEditable;
        mLitigationClauseEditText.getEditText().setEnabled(isLitigationClauseEditable);
        if (isLitigationClauseEditable) {
            mLitigationClauseEditTextView.setText("保存");
            showKeyboard(mLitigationClauseEditText.getEditText());
            String content = mLitigationClauseEditText.getContentText();
            if (!TextUtils.isEmpty(content)) {
                mLitigationClauseEditText.getEditText().setSelection(content.length());
            }
        } else {
            hideKeyboard();
            mLitigationClauseEditTextView.setText("编辑");
        }

    }


    @OnClick(R.id.activity_contract_add_step_one_supplierDistributionEditTextView)
    public void supplierDistributionEdit() {
        isSupplierDistributionEditable = !isSupplierDistributionEditable;
        mSupplierDistributionEditText.getEditText().setEnabled(isSupplierDistributionEditable);
        if (isSupplierDistributionEditable) {
            mSupplierDistributionEditTextView.setText("保存");
            showKeyboard(mSupplierDistributionEditText.getEditText());
            String content = mSupplierDistributionEditText.getContentText();
            if (!TextUtils.isEmpty(content)) {
                mSupplierDistributionEditText.getEditText().setSelection(content.length());
            }
        } else {
            hideKeyboard();
            mSupplierDistributionEditTextView.setText("编辑");
        }

    }




    public void getBianHaoResult(String bianhao) {

//        mContractInfo =new ContractInfo();
//        changeUi();

        Map<String, String> map = new HashMap<>();
        map.put("code", bianhao);
        mContractModel.getBianHaoResult(getContext(), map, true, this.bindLifecycle(), new ObserverResponseListener<CommonResponse<ContractInfo>>() {
            @Override
            public void onNext(CommonResponse<ContractInfo> commonResponse) {
                if (commonResponse.getCode() == 20000) {
                    mContractInfo = commonResponse.getData();
                    if (null!=mContractInfo) {
                        changeUi();
                    }else {
                        showToast("未找到此单号");
                    }
                } else {
                    showToast(commonResponse.getMsg());
                }

            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                showToast(e.message);
            }
        });

    }

    private void changeUi() {

        if (!TextUtils.isEmpty(mContractInfo.methodtype)) {
            mSupplierDistributionLinearLayout.setVisibility(View.VISIBLE);
            mDemanderPickLinearLayout.setVisibility(View.GONE);
            if (mContractInfo.methodtype.equals("1")) {
//                mSupplierDistributionLinearLayout.setVisibility(View.VISIBLE);
//                mDemanderPickLinearLayout.setVisibility(View.GONE);
                mDeliveryPlaceClickItemView.setContent("1、产品由需方自提");
            } else if (mContractInfo.methodtype.equals("2")){
//                mSupplierDistributionLinearLayout.setVisibility(View.GONE);
//                mDemanderPickLinearLayout.setVisibility(View.VISIBLE);
                mDeliveryPlaceClickItemView.setContent("2、甲方代办运输，运费由乙方承担，货物风险自甲方交付第一承运人起由乙方承担");
//                mDemanderPickInputItemView.setContent(mContractInfo.otherplacemethod);
            }else if (mContractInfo.methodtype.equals("3")){
                mDeliveryPlaceClickItemView.setContent("3、产品由甲方送货，运费由甲方承担");
            } else if (mContractInfo.methodtype.equals("4")){
                mDeliveryPlaceClickItemView.setContent("4、转货权");
            }else if (mContractInfo.methodtype.equals("5")){
                mDeliveryPlaceClickItemView.setContent("5、由甲方上游直发配送给乙方，具体送货时间以甲方上游送货时间为准，如与本合同约定送货时间不一致，不视为甲方逾期交货，甲方无需承担违约责任。");
            }
        }
//        else {
//            mContractInfo.methodtype = "1";
//            mDeliveryPlaceClickItemView.setContent("1、产品由需方自提");
//        }



        if (!TextUtils.isEmpty(mContractInfo.packagetype)) {
            mPackageStandardsClickItemView.setContent(mContractInfo.packagetype);
        }else {
            mContractInfo.packagetype = "原包装袋，25公斤/包。";
            mPackageStandardsClickItemView.setContent("原包袋装，25公斤/包。");
        }

        if (!TextUtils.isEmpty(mContractInfo.qualitystandard)) {
            mContractStandardTypeClickItemView.setContent(mContractInfo.qualitystandard);
        }else {
            mContractInfo.qualitystandard = "标准";
            mContractStandardTypeClickItemView.setContent("标准");
        }




        if (!TextUtils.isEmpty(mContractInfo.paytype)) {
            if ("1".equals(mContractInfo.paytype)){
                civ_jiesuan_type.setContent("现金");
            }else if ("3".equals(mContractInfo.paytype)){
                civ_jiesuan_type.setContent("银行承兑汇票");
            }else {
                civ_jiesuan_type.setContent("银行汇款");
            }

        }
//        else {
//            civ_jiesuan_type.setContent("银行汇款");
//            mContractInfo.paytype = "2";
//        }



        if (!TextUtils.isEmpty(mContractInfo.contracttype)) {
            IContractTypeView iContractTypeView = null;
            if (mContractInfo.contracttype.equals(IContractType.ADVANCE_PAYMENT)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_advance));
                iContractTypeView = new AdvancePaymentView(getContext(), new AdvancePaymentContract());
//            searchDataInFo.placemethod="汽车运输送至需方           。";
            } else if (mContractInfo.contracttype.equals(IContractType.CASH_DEPOSIT)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_cash));
                iContractTypeView = new CashDeliveryView(getContext(), new CashDepositContract());
            } else if (mContractInfo.contracttype.equals(IContractType.NO_CASH_DEPOSIT)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_no_cash));
                iContractTypeView = new NoCashDepositView(getContext(), new NoCashDepositContract());
            } else if (mContractInfo.contracttype.equals(IContractType.FUTURES_DEPOSIT)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_futures));
                iContractTypeView = new FuturesDepositView(getContext(), new FuturesDepositContract());
            } else if (mContractInfo.contracttype.equals(IContractType.ACCOUNTING_PERIOD)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_accounting));
                iContractTypeView = new ZhangQiDepositView(getContext(), new ZhangQiDepositContract());
            }else if (mContractInfo.contracttype.equals(IContractType.DIAN_JIA)) {
                mContractTypeClickItemView.setContent(getResources().getString(R.string.string_contract_type_dianjia));
                iContractTypeView = new DianJiaDepositView(getContext(), new DianJiaDepositContract());

            }

            if (iContractTypeView != null) {
                showContractTypeView(iContractTypeView);
                iContractTypeView.initViewData(mContractInfo);
            }
        }

        if (!TextUtils.isEmpty(mContractInfo.placemethod))
        mSupplierDistributionEditText.setContentText(mContractInfo.placemethod);
        if (!TextUtils.isEmpty(mContractInfo.complain))
        mLitigationClauseEditText.setContentText(mContractInfo.complain);
        if (!TextUtils.isEmpty(mContractInfo.contractno))
        mContractNumberInputItemView.setContent(mContractInfo.contractno);

        mContractInfo.isblack = "1";

    }


}
